package com.yk.neon.lib.util.result;

public class ResultUtil {

	public static BasicResponse<String> success() {
		return success(HttpCode.SUCCESS, HttpCode.SUCCESS.desc());
	}

	public static <T> BasicResponse<T> success(T data) {
		return success(HttpCode.SUCCESS, data);
	}

	public static <T> BasicResponse<T> success(HttpCode code, T data) {
		return response(code, null, data);
	}

	public static BasicResponse fail() {
		return fail(HttpCode.SERVER_ERROR, HttpCode.SERVER_ERROR.desc());
	}

	public static BasicResponse fail(HttpCode code) {
		return fail(code, code.desc());
	}

	public static BasicResponse fail(String msg) {
		return fail(HttpCode.SERVER_ERROR, msg);
	}

	public static BasicResponse fail(HttpCode code, String msg) {
		return fail(code, msg, null);
	}

	public static <T> BasicResponse<T> fail(String msg, T data) {
		return fail(HttpCode.SERVER_ERROR, msg, data);
	}

	public static <T> BasicResponse<T> fail(HttpCode code, String msg, T data) {
		return response(code, msg, data);
	}

	private static <T> BasicResponse<T> response(HttpCode code, String msg, T data) {
		BasicResponse<T> basicResponse = new BasicResponse<>();
		basicResponse.setResult(code);
		basicResponse.setMsg(msg);
		basicResponse.setData(data);
		return basicResponse;
	}

}
